package at.fhj.swd10.eshop.web.filter;

import at.fhj.swd10.eshop.domain.Product;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.richfaces.model.Filter;

/**
 * @author David
 */
@ManagedBean
@ViewScoped
public class ProductFilter implements Serializable {

    private String categoryFilter;
    private String labelFilter;

    public Filter<Product> getFilterCategory() {
        return new Filter<Product>() {

            @Override
            public boolean accept(Product p) {
                String category = getCategoryFilter();
                if (category == null || category.length() == 0 || category.equals(p.getCategory().getName())) {
                    return true;
                }
                return false;
            }
        };
    }

    public Filter<Product> getFilterLabel() {
        return new Filter<Product>() {

            @Override
            public boolean accept(Product p) {
                String label = getLabelFilter();
                if (label == null || label.length() == 0 || label.equals(p.getLabel().getName())) {
                    return true;
                }
                return false;
            }
        };
    }

    public String getCategoryFilter() {
        return categoryFilter;
    }

    public void setCategoryFilter(String categoryFilter) {
        this.categoryFilter = categoryFilter;
    }

    public String getLabelFilter() {
        return labelFilter;
    }

    public void setLabelFilter(String labelFilter) {
        this.labelFilter = labelFilter;
    }
}
